package com.tyf.bookreader.controller;

import com.tyf.bookreader.dto.CommentDTO;
import com.tyf.bookreader.dto.PageRespDto;
import com.tyf.bookreader.service.CommentService;
import com.tyf.bookreader.vo.CommentPageVo;
import com.tyf.bookreader.component.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author shallow
 * @Date 2023/4/1 18:06
 */
@RestController
@RequestMapping("comment")
@Api(tags = "评论模块")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "根据bookId分页查看本书所有评论")
    @GetMapping("bookComment")
    public Result<PageRespDto<CommentDTO>> getAllCommentByBookId(CommentPageVo commentPageVo){
        return commentService.getAllCommentByBookId(commentPageVo);
    }

    @ApiOperation(value = "获得本书热门评论")
    @GetMapping("hotComment/{bookId}")
    public Result<List<CommentDTO>> getHotCommentsById(@PathVariable("bookId") Long bookId){
        return commentService.getHotCommentsById(bookId);
    }

    @ApiOperation(value = "分页获得该评论的回复")
    @GetMapping("getChildComment")
    public Result<PageRespDto<CommentDTO>> getChildComment(CommentPageVo commentPageVo){
        return commentService.getChildComment(commentPageVo);
    }

    @ApiOperation(value = "点赞评论")
    @PostMapping("star")
    public Result saveCommentLike(@RequestParam("commentId") Long commentId){
        return commentService.saveCommentLike(commentId);
    }
}
